package project.dade.cn.bst.adapter.base;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewAdapter;
import cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper;
import project.dade.cn.bst.R;
import project.dade.cn.bst.model.OrderDatailModel;
import project.dade.cn.bst.utils.LogUtil;
import project.dade.cn.bst.utils.ULog;

/**
 * Created by vain zhou on 2016/4/21.
 */
public class OrderDatailAdapter extends BGARecyclerViewAdapter<OrderDatailModel.DataBean.OrderProductsBean> {
    private Button comment;
    private TextView refund;
    private LinearLayout bar_comment;
    private LinearLayout bar_refund;
    private TextView paid;

    public OrderDatailAdapter(RecyclerView recyclerView) {
        super(recyclerView, R.layout.adapter_order);

    }
    public void setItemChildListener(final BGAViewHolderHelper helper) {
        helper.setItemChildClickListener(R.id.btn_order_comment);//退货或评价
    }

    protected void fillData(BGAViewHolderHelper helper, int postion, OrderDatailModel.DataBean.OrderProductsBean model) {
        helper.setText(R.id.tv_title, model.getProductName());
        helper.setText(R.id.tv_sell, model.getTotalPrice() + "");
        helper.setText(R.id.tv_num, model.getQuantity() + "");
        ImageView avatorIv = helper.getView(R.id.photo);
        bar_comment = helper.getView(R.id.line_comment);
        comment = helper.getView(R.id.btn_order_comment);
        bar_refund = helper.getView(R.id.label_refund);
        refund = helper.getView(R.id.refund);
        Glide.with(mContext).load(model.getProductImage()).placeholder(R.drawable.image_loader_small).error(R.drawable.image_loader_small).into(avatorIv);
        comment = helper.getView(R.id.btn_order_comment);
        refund = helper.getTextView(R.id.refund);
       helper.setText(R.id.tv_paid,model.getFactPrice()+"");

        if(model.getIsSigned()==1/*已签收*/)
        {
           comment.setVisibility(View.VISIBLE);
            if(model.getCommentType()==0/*未评论*/)
            {
                //显示评论按钮
                bar_comment.setVisibility(View.VISIBLE);
                comment.setText("评论商品");

            }

        }
        else
        {
            if (model.getPaymentStatus() == 1) {

                if (model.getIsRefund().equals("0"))/*未申请退款*/ {
                    //显示退款申请按钮
                   bar_comment.setVisibility(View.VISIBLE);
                   comment.setText("申请退款");
                }
                if (model.getIsRefund().equals("1"))/*该商品已申请退款*/ {
                    //显示退款状态
                    String refundState=model.getRefundState().trim();
                    if (refundState.equals("0"))/*退款等待审核*/ {

                        //等待退款审核
                        bar_comment.setVisibility(View.GONE);
                       bar_refund.setVisibility(View.VISIBLE);
                        refund.setText("等待审核");
                    }
                    if (refundState.equals("1"))/*等待退款*/ {;
                        //等待退款
                        bar_comment.setVisibility(View.GONE);
                       bar_refund.setVisibility(View.VISIBLE);
                        refund.setText("等待退款");
                    }
                    if (refundState.equals("2") )/*等待买家退货*/{
                        //等待买家退货
                        bar_comment.setVisibility(View.GONE);
                        bar_refund.setVisibility(View.VISIBLE);
                        refund.setText("等待买家退货");
                    }
                    if (refundState.equals("3"))/*已退款*/ {
                        //已退款
                        bar_comment.setVisibility(View.GONE);
                        bar_refund.setVisibility(View.VISIBLE);
                        refund.setText("卖家已退款");
                    }
                    if (refundState.equals("4"))/*卖家拒绝退款*/ {
                        //卖家拒绝退款
                        bar_comment.setVisibility(View.GONE);
                        bar_refund.setVisibility(View.VISIBLE);
                        refund.setText("卖家拒绝退款");
                    }
                }
            }
        }

    }
}
